package code.tools.log
{
	import flash.utils.getQualifiedClassName;
	
	/**
	 * @author wenqiang.deng
	 */
	public class Logger
	{
		private static var _targets : Vector.<ILogTarget> = new Vector.<ILogTarget>();
		
		/**
		 *添加日志输出平台
		 * @param target
		 * 
		 */		
		public static function addTarget(target : ILogTarget) : void
		{
			_targets.push(target);
		}
			
		/**
		 *输出 
		 * @param title
		 * @param message
		 * @param error
		 * 
		 */		
		public static function trace(title:Object,message : String, error : Error = null) : void
		{
			output(LogLevel.TRACE,title, message, error);
		}
		
		/**
		 * debug
		 * @param title
		 * @param message
		 * @param error
		 * 
		 */		
		public static function debug(title:Object,message : String, error : Error = null) : void
		{
			output(LogLevel.DEBUG,title, message, error);
		}
		
		/**
		 *消息 
		 * @param title
		 * @param message
		 * @param error
		 * 
		 */		
		public static function info(title:Object,message : String, error : Error = null) : void
		{
			output(LogLevel.INFO,title, message, error);
		}
		
		/**
		 *警告 
		 * @param title
		 * @param message
		 * @param error
		 * 
		 */		
		public static function warn(title:Object,message : String, error : Error = null) : void
		{
			output(LogLevel.WARN,title, message, error);
		}
		
		/**
		 *错误信息 
		 * @param title
		 * @param message
		 * @param error
		 * 
		 */		
		public static function error(title:Object,message : String, error : Error = null) : void
		{
			output(LogLevel.ERROR,title, message, error);
		}
		
		/**
		 *崩溃信息
		 * @param title
		 * @param message
		 * @param error
		 * 
		 */		
		public static function fatal(title:Object,message : String, error : Error = null) : void
		{
			output(LogLevel.FATAL,title, message, error);
		}
		
		private static function output(level : LogLevel,title:Object, message : String, error : Error = null) : void
		{
			var name:String = typeof title == 'object' ? getQualifiedClassName(title) : String(title);
			for (var i : int = 0;i < _targets.length;i++)
			{
				_targets[i].output(level, name, message, error);
			}
		}
	}
}
